using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using log4net;
using Triton.Common;
using Triton.Common.LogUtilities;
using Triton.Game;
using Triton.Game.Data;
using Triton.Game.Mapping;

namespace Triton.Bot
{
	public class GameEventManager : IRunnable, IResetable
	{
		private static readonly ILog ilog_0 = Triton.Common.LogUtilities.Logger.GetLoggerInstanceForType();

		private const string string_0 = "77885";

		private int int_0 = -1;

		private int int_1;

		private readonly Stopwatch stopwatch_0 = new Stopwatch();

		private PresenceStatus presenceStatus_0 = PresenceStatus.UNKNOWN;

		private static GameEventManager gameEventManager_0;

		[CompilerGenerated]
		private static EventHandler<NewGameEventArgs> eventHandler_0;

		[CompilerGenerated]
		private static EventHandler<QuestLoadEventArgs> eventHandler_1;

		[CompilerGenerated]
		private static EventHandler<QuestUpdateEventArgs> eventHandler_2;

		[CompilerGenerated]
		private static EventHandler<ArenaRewardsEventArgs> eventHandler_3;

		[CompilerGenerated]
		private static EventHandler<GameOverEventArgs> eventHandler_4;

		[CompilerGenerated]
		private static EventHandler<MulliganConfirmEventArgs> eventHandler_5;

		[CompilerGenerated]
		private static EventHandler<PreStartingNewGameEventArgs> eventHandler_6;

		[CompilerGenerated]
		private static EventHandler<StartingNewGameEventArgs> eventHandler_7;

		[CompilerGenerated]
		private static EventHandler<CustomDecksCachedEventArgs> eventHandler_8;

		[CompilerGenerated]
		private static EventHandler<FatalErrorEventArgs> eventHandler_9;

		public PresenceStatus LastGamePresenceStatus => presenceStatus_0;

		public static GameEventManager Instance => gameEventManager_0 ?? (gameEventManager_0 = new GameEventManager());

		public static event EventHandler<NewGameEventArgs> NewGame
		{
			[CompilerGenerated]
			add
			{
				EventHandler<NewGameEventArgs> eventHandler = eventHandler_0;
				EventHandler<NewGameEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<NewGameEventArgs> value2 = (EventHandler<NewGameEventArgs>)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_0, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				EventHandler<NewGameEventArgs> eventHandler = eventHandler_0;
				EventHandler<NewGameEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<NewGameEventArgs> value2 = (EventHandler<NewGameEventArgs>)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_0, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
		}

		public static event EventHandler<QuestLoadEventArgs> QuestLoad
		{
			[CompilerGenerated]
			add
			{
				EventHandler<QuestLoadEventArgs> eventHandler = eventHandler_1;
				EventHandler<QuestLoadEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<QuestLoadEventArgs> value2 = (EventHandler<QuestLoadEventArgs>)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_1, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				EventHandler<QuestLoadEventArgs> eventHandler = eventHandler_1;
				EventHandler<QuestLoadEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<QuestLoadEventArgs> value2 = (EventHandler<QuestLoadEventArgs>)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_1, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
		}

		public static event EventHandler<QuestUpdateEventArgs> QuestUpdate
		{
			[CompilerGenerated]
			add
			{
				EventHandler<QuestUpdateEventArgs> eventHandler = eventHandler_2;
				EventHandler<QuestUpdateEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<QuestUpdateEventArgs> value2 = (EventHandler<QuestUpdateEventArgs>)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_2, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				EventHandler<QuestUpdateEventArgs> eventHandler = eventHandler_2;
				EventHandler<QuestUpdateEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<QuestUpdateEventArgs> value2 = (EventHandler<QuestUpdateEventArgs>)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_2, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
		}

		public static event EventHandler<ArenaRewardsEventArgs> ArenaRewards
		{
			[CompilerGenerated]
			add
			{
				EventHandler<ArenaRewardsEventArgs> eventHandler = eventHandler_3;
				EventHandler<ArenaRewardsEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<ArenaRewardsEventArgs> value2 = (EventHandler<ArenaRewardsEventArgs>)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_3, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				EventHandler<ArenaRewardsEventArgs> eventHandler = eventHandler_3;
				EventHandler<ArenaRewardsEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<ArenaRewardsEventArgs> value2 = (EventHandler<ArenaRewardsEventArgs>)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_3, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
		}

		public static event EventHandler<GameOverEventArgs> GameOver
		{
			[CompilerGenerated]
			add
			{
				EventHandler<GameOverEventArgs> eventHandler = eventHandler_4;
				EventHandler<GameOverEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<GameOverEventArgs> value2 = (EventHandler<GameOverEventArgs>)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_4, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				EventHandler<GameOverEventArgs> eventHandler = eventHandler_4;
				EventHandler<GameOverEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<GameOverEventArgs> value2 = (EventHandler<GameOverEventArgs>)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_4, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
		}

		public static event EventHandler<MulliganConfirmEventArgs> MulliganConfirm
		{
			[CompilerGenerated]
			add
			{
				EventHandler<MulliganConfirmEventArgs> eventHandler = eventHandler_5;
				EventHandler<MulliganConfirmEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<MulliganConfirmEventArgs> value2 = (EventHandler<MulliganConfirmEventArgs>)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_5, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				EventHandler<MulliganConfirmEventArgs> eventHandler = eventHandler_5;
				EventHandler<MulliganConfirmEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<MulliganConfirmEventArgs> value2 = (EventHandler<MulliganConfirmEventArgs>)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_5, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
		}

		public static event EventHandler<PreStartingNewGameEventArgs> PreStartingNewGame
		{
			[CompilerGenerated]
			add
			{
				EventHandler<PreStartingNewGameEventArgs> eventHandler = eventHandler_6;
				EventHandler<PreStartingNewGameEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<PreStartingNewGameEventArgs> value2 = (EventHandler<PreStartingNewGameEventArgs>)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_6, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				EventHandler<PreStartingNewGameEventArgs> eventHandler = eventHandler_6;
				EventHandler<PreStartingNewGameEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<PreStartingNewGameEventArgs> value2 = (EventHandler<PreStartingNewGameEventArgs>)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_6, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
		}

		public static event EventHandler<StartingNewGameEventArgs> StartingNewGame
		{
			[CompilerGenerated]
			add
			{
				EventHandler<StartingNewGameEventArgs> eventHandler = eventHandler_7;
				EventHandler<StartingNewGameEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<StartingNewGameEventArgs> value2 = (EventHandler<StartingNewGameEventArgs>)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_7, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				EventHandler<StartingNewGameEventArgs> eventHandler = eventHandler_7;
				EventHandler<StartingNewGameEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<StartingNewGameEventArgs> value2 = (EventHandler<StartingNewGameEventArgs>)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_7, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
		}

		public static event EventHandler<CustomDecksCachedEventArgs> CustomDecksCached
		{
			[CompilerGenerated]
			add
			{
				EventHandler<CustomDecksCachedEventArgs> eventHandler = eventHandler_8;
				EventHandler<CustomDecksCachedEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<CustomDecksCachedEventArgs> value2 = (EventHandler<CustomDecksCachedEventArgs>)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_8, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				EventHandler<CustomDecksCachedEventArgs> eventHandler = eventHandler_8;
				EventHandler<CustomDecksCachedEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<CustomDecksCachedEventArgs> value2 = (EventHandler<CustomDecksCachedEventArgs>)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_8, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
		}

		public static event EventHandler<FatalErrorEventArgs> FatalError
		{
			[CompilerGenerated]
			add
			{
				EventHandler<FatalErrorEventArgs> eventHandler = eventHandler_9;
				EventHandler<FatalErrorEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<FatalErrorEventArgs> value2 = (EventHandler<FatalErrorEventArgs>)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_9, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				EventHandler<FatalErrorEventArgs> eventHandler = eventHandler_9;
				EventHandler<FatalErrorEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<FatalErrorEventArgs> value2 = (EventHandler<FatalErrorEventArgs>)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange(ref eventHandler_9, value2, eventHandler2);
				}
				while ((object)eventHandler != eventHandler2);
			}
		}

		internal void method_0(PresenceStatus presenceStatus_1)
		{
			presenceStatus_0 = presenceStatus_1;
		}

		public void Reset()
		{
			int_1 = 0;
			int_0 = -1;
			stopwatch_0.Reset();
		}

		public void Start()
		{
		}

		public void Tick()
		{
			using (new PerformanceTimer("NewGame"))
			{
				bool flag = true;
				Network network = Network.Get();
				if (network != null)
				{
					GameServerInfo lastGameServerInfo = network.m_lastGameServerInfo;
					if (Network.IsConnectedToGameServer() && lastGameServerInfo != null && int_1 != lastGameServerInfo.GameHandle)
					{
						int_1 = lastGameServerInfo.GameHandle;
						int_0 = -1;
						stopwatch_0.Restart();
						flag = false;
						TritonHs.InvokeEvent(eventHandler_0, this, new NewGameEventArgs(int_1));
					}
				}
				if (flag)
				{
					stopwatch_0.Reset();
				}
			}
		}

		public void Stop()
		{
		}

		internal void method_1()
		{
			TritonHs.InvokeEvent(eventHandler_5, this, new MulliganConfirmEventArgs());
		}

		internal void method_2()
		{
			TritonHs.InvokeEvent(eventHandler_1, this, new QuestLoadEventArgs());
		}

		internal void method_3()
		{
			TritonHs.InvokeEvent(eventHandler_2, this, new QuestUpdateEventArgs());
		}

		internal void method_4(List<Triton.Game.Data.RewardData> list_0)
		{
			TritonHs.InvokeEvent(eventHandler_3, this, new ArenaRewardsEventArgs(list_0));
		}

		internal void method_5(GameOverFlag gameOverFlag_0, bool bool_0)
		{
			if (int_0 != int_1)
			{
				int_0 = int_1;
				TritonHs.InvokeEvent(eventHandler_4, this, new GameOverEventArgs(gameOverFlag_0, bool_0));
			}
		}

		internal void method_6()
		{
			TritonHs.InvokeEvent(eventHandler_6, this, new PreStartingNewGameEventArgs());
		}

		internal void method_7()
		{
			TritonHs.InvokeEvent(eventHandler_7, this, new StartingNewGameEventArgs());
		}

		internal void method_8()
		{
			TritonHs.InvokeEvent(eventHandler_8, this, new CustomDecksCachedEventArgs());
		}

		internal void method_9()
		{
			TritonHs.InvokeEvent(eventHandler_9, this, new FatalErrorEventArgs());
		}
	}
}
